package com.binest.projectInclusion.controller;



import com.binest.common.core.controller.BaseController;
import com.binest.common.core.domain.AjaxResult;
import com.binest.common.core.page.TableDataInfo;
import com.binest.common.utils.poi.ExcelUtil;
import com.binest.projectInclusion.domain.ProjectInclusion;
import com.binest.projectInclusion.service.IProjectInclusionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * LabelController
 * 
 * @author wwd
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/projectInclusion")
public class ProjectInclusionController extends BaseController
{
    @Autowired
    private IProjectInclusionService projectInclusionService;

    /**
     * 查询项目收录列表
     */

    @GetMapping("/list")
    public TableDataInfo list(ProjectInclusion projectInclusion)
    {
        startPage();
        List<ProjectInclusion> list = projectInclusionService.selectProjectInclusionList(projectInclusion);
        return getDataTable(list);
    }


    /**
     * 查询es中项目收录列表
     */
    @GetMapping("/esList")
    public TableDataInfo esList(ProjectInclusion projectInclusion) throws Exception {

        TableDataInfo list = projectInclusionService.selectProjectInclusionEsList(projectInclusion);
        return list;
    }


    /**
     * 查询中项目收录推荐列表
     */
    @GetMapping("/recommendEsList")
    public TableDataInfo recommendEsList(ProjectInclusion projectInclusion) throws Exception {

        TableDataInfo list = projectInclusionService.selectProjectInclusionRecommendEsList(projectInclusion);
        return list;
    }

    /**
     * 导出项目收录列表
     */


    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectInclusion projectInclusion)
    {
        List<ProjectInclusion> list = projectInclusionService.selectProjectInclusionList(projectInclusion);
        ExcelUtil<ProjectInclusion> util = new ExcelUtil<ProjectInclusion>(ProjectInclusion.class);
        util.exportExcel(response, list, "项目收录数据");
    }

    /**
     * 获取项目收录详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(projectInclusionService.selectProjectInclusionById(id));
    }
    /**
     * 获取es中项目收录详细信息
     */
    @GetMapping(value = "/getEsInfo")
    public AjaxResult getEsInfo(String id) throws Exception {
        return success(projectInclusionService.selectEsProjectInclusionById(id));
    }

    /**
     * 新增项目收录
     */


    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProjectInclusion projectInclusion)
    {
        return success(projectInclusionService.insertProjectInclusion(projectInclusion));
    }
    @PostMapping("/update")
    public AjaxResult update(@RequestBody ProjectInclusion projectInclusion)
    {
        return success(projectInclusionService.insertNewProjectInclusion(projectInclusion));
    }

    /**
     * 修改项目收录
     */


    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ProjectInclusion projectInclusion)
    {
        return toAjax(projectInclusionService.updateProjectInclusion(projectInclusion));
    }

    /**
     * 删除项目收录
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(projectInclusionService.deleteProjectInclusionByIds(ids));
    }
}
